//
//  AdvancedIdentifyViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/3/11.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "AdvancedIdentifyViewController.h"
#import "AdvancedIdentify2ViewController.h"
#import "AdvancedIdentifyView.h"
#import "AdvancedIdentifyTableViewCell.h"

@interface AdvancedIdentifyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UIButton *nextStypeBtn;
@property(nonatomic,strong)AdvancedIdentifyView *av;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *titleArray;
@property(nonatomic,strong)NSMutableArray *titleValueArray;
@property(nonatomic,strong)NSMutableArray *attTitleValueArray;


@end

@implementation AdvancedIdentifyViewController

-(NSMutableArray *)titleArray
{
    if (_titleArray == nil) {
        _titleArray = [NSMutableArray array];
    }
    return _titleArray;
}
-(NSMutableArray *)titleValueArray
{
    if (_titleValueArray == nil) {
        _titleValueArray = [NSMutableArray array];
    }
    return _titleValueArray;
}
-(NSMutableArray *)attTitleValueArray
{
    if (_attTitleValueArray == nil) {
        _attTitleValueArray = [NSMutableArray array];
    }
    return _attTitleValueArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"高级认证";
    self.view.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:244 / 255.0 blue:246 / 255.0 alpha:1];
    //创建顶部基本信息展示View
    [self createTopView];
    //下一步
    [self createNextStype];
    //创建tableView
    [self createTableView];
}

-(void)createTopView
{
    self.av = [[AdvancedIdentifyView alloc] init];
    self.av.backgroundColor = [UIColor whiteColor];
    self.av.frame = CGRectMake(0, 0, self.view.frame.size.width, 51);
    [self.view addSubview:self.av];
}

-(void)createNextStype
{
    self.nextStypeBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.nextStypeBtn.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.9 alpha:1];
    [self.nextStypeBtn setTitle:@"下一步" forState:(UIControlStateNormal)];
    [self.nextStypeBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.nextStypeBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    self.nextStypeBtn.frame = CGRectMake(0, self.view.frame.size.height - ETTopHeight - ETTabBarArcHeight - 44, self.view.frame.size.width, 44);
    [self.view addSubview:self.nextStypeBtn];
    [self.nextStypeBtn addTarget:self action:@selector(nextStypeBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
}

-(void)createTableView
{
    self.titleArray = @[@"姓名",@"手机号",@"店铺名称",@"所在地"].mutableCopy;
    self.titleValueArray = @[@"请输入真实姓名",@"请输入您的手机号",@"请输入店铺名称(7~14个字符)",@"请选择您所在的地区"].mutableCopy;
    
    for (int i = 0; i < self.titleValueArray.count; i++) {
        NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:self.titleValueArray[i]];
        [placeholder addAttribute:NSForegroundColorAttributeName
                            value:[UIColor colorWithRed:221 / 255.0 green:221 / 255.0 blue:221 / 255.0 alpha:1]
                            range:NSMakeRange(0, [self.titleValueArray[i] length])];
        [placeholder addAttribute:NSFontAttributeName
                            value:[UIFont systemFontOfSize:16]
                            range:NSMakeRange(0, [self.titleValueArray[i] length])];
        
        [self.attTitleValueArray addObject:placeholder];
    }
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, ETScreenW, ETScreenH - 50 - ETTopHeight - ETTabBarArcHeight - 44) style:(UITableViewStyleGrouped)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[AdvancedIdentifyTableViewCell class] forCellReuseIdentifier:@"cell"];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AdvancedIdentifyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.titleLab.text = self.titleArray[indexPath.row];
    cell.titleValueTf.attributedPlaceholder = self.attTitleValueArray[indexPath.row];
    //点击不变色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}


-(void)nextStypeBtnAction
{
    AdvancedIdentify2ViewController *advancedVC = [[AdvancedIdentify2ViewController alloc] init];
    [self.navigationController pushViewController:advancedVC animated:YES];
}


@end
